package com.hsnn.medstgmini.base.dict.controller;


import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hsnn.medstgmini.base.dict.service.DicExperttypeLogManager;
import com.hsnn.medstgmini.util.Pagination;


/**
 * @category 专家 类型日志
 * @author wangbing
 * @date 2015年7月13日
 */
@Controller
@RequestMapping("/dicExperttypeLog")
public class DicExperttypeLogController {

	private static final Logger log = Logger.getLogger(DicExperttypeLogController.class);
			

	@Autowired
	private DicExperttypeLogManager dicExperttypeLogManager;

	@Autowired
	private HttpServletRequest request;
	
	
	/**
	 * @category 跳转专家 类型日志页面
	 * @date 2015年7月13日
	 * @return String
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping("/log")
	public String toExperttypeLogList() throws UnsupportedEncodingException {
		printParams();
		request.setAttribute("dicExperttypeId", request.getParameter("dicExperttypeId"));
		String expertTypeName = new String(request.getParameter("expertTypeName").getBytes("ISO8859-1"),"utf-8");
		request.setAttribute("expertTypeName", expertTypeName);
		return "/base/dict/experttypeLogList";
	}
	
	/**
	 * @category 获取专家 类型日志列表
	 * @date 2015年7月13日
	 * @return page
	 */
	@RequestMapping("/getDicExperttypeLogList")
	@ResponseBody
	public Pagination getDicExperttypeLogList(){
		printParams();
		Pagination page = new Pagination(request);
		try {
			page.getConditions().put("dicExperttypeId", request.getParameter("dicExperttypeId"));
			page.getConditions().put("startDate", request.getParameter("startDate"));
			page.getConditions().put("endDate", request.getParameter("endDate"));
			dicExperttypeLogManager.getDicExperttypeLogList(page);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return page;
	}
	
	
	/**
	 * 基础库 数据字典 剂型字典 根据id查询剂型 日志详情
	 * @param result
	 * @param dicDrugformLog
	 * @return
	 */
	@RequestMapping("/toDicExperttypeLogListDetail")
	public String toDicExperttypeLogListDetail(){
		printParams();
		Pagination  page = new Pagination();
		page.getConditions().put("logId", request.getParameter("logId"));
		List<Map<String,Object>> list = dicExperttypeLogManager.getDicExperttypeLogListDetail(page);
		request.setAttribute("list", list);
		return "/base/dict/experttypeLogListDetail";
		
	}
	
	/**
	 * 
	 *@category 获取参数打印
	 *@author 徐国鹏
	 *@date 2015年6月9日
	 *Pagination
	 */
	@SuppressWarnings("rawtypes")
	public void printParams(){
		Enumeration paramNames = request.getParameterNames();
		try {
			while (paramNames.hasMoreElements()) {
				String paramName = (String) paramNames.nextElement();
				String paramValue = request.getParameter(paramName);
				log.info(paramName+":"+paramValue);
			}
		} catch (Exception e) {
			log.error("",e);
		}
	}
	
}
